<template>
    <div class="foot">
        <van-goods-action>
            <!-- 基础样式有点击 -->
            <van-goods-action-icon icon="chat-o" text="客服" @click="toCustomer(arrPre)"/>
            <van-goods-action-icon icon="cart-o" text="购物车" @click="$router.push('/cart')"/>
            <van-goods-action-icon icon="shop-o" text="店铺" />
            <van-goods-action-button type="warning" text="加入购物车" @click="goCart(arrPre)"/>
            <van-goods-action-button type="danger" text="立即购买" @click="goOrder(arrPre)"/>
        </van-goods-action>
    </div>
</template>

<script>

export default {
    data() {
        return {
            token: '',
            list:[]
          
                }
    },
    // 收首页商品数据
    props: ["arrPre"],

    methods: {
      async  goCart(arrPre) {
            // 请求加入购物车
            // proid父传子
            const { data: res }=await this.$http.post('http://118.178.238.19:3001/api/cart/add', {
                token: localStorage.getItem("token"),
                userid: "user_075616fe-8528-43e9-ba98-9dd0c4db8873",
                proid: arrPre.proid,
                num:"1"
            })
            if (localStorage.getItem("token")) {
                //  加入，更新数据
                const { data: res1 } = await this.$http.post('http://118.178.238.19:3001/api/cart/updatenum', {
                    token: localStorage.getItem("token"),
                    cartid: arrPre.cartid,
                    num: 1
                })

            } else {
                this.$router.push("/loginCode")
            }
           
        },
        goOrder(arrPre) {
            this.list.push(arrPre)
            this.$router.push({
                path: '/order',
                query: {
                    listOrder: JSON.stringify(this.list)
                }
           })
        }
        ,
        toCustomer(arrPre){
            if(localStorage.getItem("token")){
                this.$router.push({
                    path: '/CustomerPage',
                    // 本地存储则不需要传参，直接get
                    query: {
                        arrPre: JSON.stringify(arrPre),
                    }
                })
            }else{
                this.$router.push("/loginCode")
            }
            
        } 
    },
  async  mounted() {
    }
      
}
</script>

<style scoped>
.foot{
    margin-top: 1.5rem;
}
</style>